<?php
/**
 * Created by PhpStorm.
 * User: tony
 * Date: 2018/6/4
 * Time: 11:20
 */

namespace app\modules\v1\controllers;

use app\config\Status;
use app\models\Task;
use app\models\TaskFlow;
use app\modules\v1\controllers\parent\ParentController;
use yii\data\ActiveDataProvider;

class TaskFlowController extends ParentController
{
    /**
     * @throws \yii\base\InvalidConfigException
     */
    public function actionCreate(){
        $params = \Yii::$app->request->getBodyParams();
        $task_id = (int)$params['task_id'];
        if(Task::findOne($task_id)->status !== 1)
            return [
                'bCode' => Status::FAIL,
                'bData' => ['msg'=>'该任务已完成或未在执行']
            ];
        $taskFlow = new TaskFlow();
        $taskFlow->load($params,'');
        $taskFlow->created_at = $taskFlow->updated_at = time();
        if($taskFlow->save()){
            return [
                'bCode' => Status::SUCCESS,
                'bData' => $taskFlow
            ];
        }
        return [
            'bCode' => Status::FAIL,
            'bData' => $taskFlow->errors
        ];

    }
}